package com.google.code.gronono.gps.ui.panels;

import java.awt.Color;
import java.awt.Font;

import javax.swing.GroupLayout;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;

/**
 * Panneau affichant les informations sur la page en cours.
 *
 * @author Arnaud BRUNET
 */
public class HeaderPanel extends JPanel {
	 /** serialVersionUID */
	private static final long serialVersionUID = 3981247473455208144L;

	/** Le titre de la page. */
	private JLabel titleLbl;
	/** L'icône de la page. */
	private JLabel iconLbl;
	/** La description de la page. */
	private JLabel descriptionLbl;
	/** Le séparateur entre le header et le reste de l'application. */
	private JSeparator separator;

	/**
	 * Construit le panneau.
	 */
    public HeaderPanel() {
        initComponents();
        placeComponents();
    }

    /**
     * Initialise les différents composants.
     */
	private void initComponents() {
        titleLbl = new JLabel();
        titleLbl.setFont(titleLbl.getFont().deriveFont(Font.BOLD));
        descriptionLbl = new JLabel();
        descriptionLbl.setVerticalAlignment(SwingConstants.TOP);
        iconLbl = new JLabel();
        separator = new JSeparator();

        setBackground(Color.WHITE);
    }

	/**
     * Place les composants dans le panneau.
     */
	private void placeComponents() {
		final GroupLayout layout = new GroupLayout(this);
        this.setLayout(layout);

        // Horizontalement
        layout.setHorizontalGroup(
                layout.createParallelGroup()
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup()
                        .addComponent(separator, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createSequentialGroup()
                        	.addContainerGap()
                            .addGroup(layout.createParallelGroup()
                                .addComponent(titleLbl)
                                .addGroup(layout.createSequentialGroup()
                                	.addGap(10, 10, 10)
                                	.addComponent(descriptionLbl, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addPreferredGap(ComponentPlacement.RELATED)
                            .addComponent(iconLbl))))
            );
		// Verticalement
        layout.setVerticalGroup(
                layout.createParallelGroup()
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(Alignment.LEADING, false)
                        .addComponent(iconLbl)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(titleLbl)
                            .addPreferredGap(ComponentPlacement.RELATED)
                            .addComponent(descriptionLbl, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(separator, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        );
	}

	/**
	 * Change le titre de la page.
	 * @param title Le nouveau titre de la page.
	 */
	public void setTitle(String title) {
		this.titleLbl.setText(title);
	}

	/**
	 * Change la description de la page.
	 * @param description La nouvelle description de la page.
	 */
	public void setDescription(String description) {
		this.descriptionLbl.setText(description);
	}

	/**
	 * Change l'icone de la page.
	 * @param icon Le nouvel icone de la page.
	 */
	public void setIcon(Icon icon) {
		this.iconLbl.setIcon(icon);
	}

}
